//
//  WCNChooseView.m
//  时间选择
//
//  Created by wsj2015 on 15/9/18.
//  Copyright (c) 2015年 wsj2015. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Macros.h"
@interface MyButton : UIButton



@end
@implementation MyButton
{
   
    CGRect _oriFrame;
    
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
//        self.backgroundColor =[UIColor whiteColor];
    
      
   
        
        
    }
    return self;
}
- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
  
    if (selected == YES) {
        
    }
    
}

@end

#import "WCNChooseView.h"
#import "WSJAnimationTool.h"


@implementation WCNChooseView
{
    NSInteger _selectIndex;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        NSArray *titleArray =@[@"一",@"二",@"三",@"四",@"五",@"六",@"日"];
        CGFloat w =frame.size.width / 7;
        CGFloat h =frame.size.height;
        
        self.layer.borderColor = kBorderColor.CGColor;
        self.layer.borderWidth = 0.8f;
        for (int i = 0; i<7; i++) {
            MyButton *btn =[MyButton buttonWithType:UIButtonTypeCustom];
            btn.frame =CGRectMake( i *w, 0, w, h);
            btn.tag =200 + i;
            [btn addTarget:self action:@selector(chooseAction:) forControlEvents:UIControlEventTouchUpInside];
            [btn setTitle:titleArray[i] forState:UIControlStateNormal];
             [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [btn setBackgroundColor:[UIColor clearColor]];
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            if (i == 0) {
                btn.selected =YES;
                btn.backgroundColor = [UIColor redColor];
                _selectIndex = i;
               
            }
            [self addSubview:btn];
            
        }
        
    }
    return self;
  
}
- (void)chooseAction:(UIButton *)btn
{
    NSLog(@"%@",btn.currentTitle);
    UIButton *preBtn =(UIButton *)[self viewWithTag:_selectIndex +200];
    if (preBtn == btn) {
        return;
    }
    [WSJAnimationTool animationCurlUp:preBtn];
    [WSJAnimationTool animationCubeFromTop:btn];
    preBtn.selected =NO;
    [preBtn setBackgroundColor:[UIColor clearColor]];
   
    [btn setBackgroundColor:[UIColor redColor]];
    
    btn.selected =YES;
    if (self.chooseBlock) {
        self.chooseBlock(btn.tag -200);
    }
      _selectIndex =btn.tag -200;

}
@end

